#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${package}.infrastructure.persistent.repository.user.mapstruct;

import ${package}.domain.user.model.entity.UserEntity;
import ${package}.infrastructure.persistent.po.UserPO;
import org.mapstruct.Mapper;// 注意导包不要出错
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

import java.util.List;
// 可以安装插件MapStruct Support
// 也可以不使用MapStruct，而使用set方法
@Mapper
public interface UserPOConvert {
    UserPOConvert INSTANCE = Mappers.getMapper(UserPOConvert.class);
    // source是入参的成员变量名，target是目标类的成员变量名
    @Mappings({
            @Mapping(source = "id", target = "id"),
            @Mapping(source = "name", target = "name"),
            @Mapping(source = "password", target = "password"),
            // 使用了expression就不需要source
            // 将枚举转化为数字，可以下载插件MapStruct Support，这样就能解析expression中的内容了,GenderEnum需要使用全路径，否则找不到类
            @Mapping(target = "gender" ,expression = "java(${package}.domain.user.model.valobj.GenderEnum.getCode(userEntity.getGender()))"),
            @Mapping(source = "updateTime", target = "updateTime"),
    })
    UserPO convertUserEntityToUserPO(UserEntity userEntity);

    // 对于变量名相同的，且不需要做特殊处理的，可以不写source和target
    @Mappings({
            // 使用了expression就不需要source
            // 将数字转化为枚举
            @Mapping(target = "gender" ,expression = "java(${package}.domain.user.model.valobj.GenderEnum.getGenderEnumByCode(userPO.getGender()))"),
    })
    UserEntity convertUserPOToUserEntity(UserPO userPO);

    // 批量转换，会依据单体转换的规则进行转换
    List<UserPO> convertUserEntityToUserPOList(List<UserEntity> userEntityList);

    List<UserEntity> convertUserPOToUserEntityList(List<UserPO> userPOList);
}
